﻿@page "/input"

@* <p>
    <input @bind="inputValue" />
</p>

<p>
    <input @bind="InputValue" />
</p>

<ul>
    <li><code>inputValue</code>: @inputValue</li>
    <li><code>InputValue</code>: @InputValue</li>
</ul>

@code {
    private string? inputValue;

    private string? InputValue { get; set; }
} *@


@* 
<p>
    <input @bind="InputValue" @bind:after="InputAfter" />
</p>

<p>
    <code>InputValue</code>: @InputValue
</p>

@message

@code {
    private string? InputValue { get; set; }


    string? message;
    void InputAfter()
    {
        message = "输入后得到";
    }
} *@


@* <p>
    <input @bind:get="text" @bind:set="OnInput" />
</p>

@code{
    string? text;

    private void OnInput(string value)
    {
        var newValue = value ?? string.Empty;

        text = newValue.Length > 4 ? "Long!" : newValue;
    }
} *@


@* 
@using System.Globalization

<p>
    <label>
        Decimal value (±0.000 format):
        <input @bind="DecimalValue" />
    </label>
</p>

<p>
    <code>decimalValue</code>: @decimalValue
</p>

@code {
    private decimal decimalValue = 1.1M;
    private NumberStyles style =
        NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign;
    private CultureInfo culture = CultureInfo.CreateSpecificCulture("zh-CN");

    private string DecimalValue
    {
        get => decimalValue.ToString("0.000", culture);
        set
        {
            if (Decimal.TryParse(value, style, culture, out var number))
            {
                decimalValue = Math.Round(number, 3);
            }
        }
    }
} *@


@* <p>
    <label>
        选择一个品牌：
        <select @onchange="SelectedCarsChanged">
            <option value="奥体">奥迪</option>
            <option value="大众">大众</option>
            <option value="丰田">丰田</option>
            <option value="比亚迪">比亚迪</option>
            <option value="沃尔沃">沃尔沃</option>
        </select>
    </label>
</p>

<p>
    选择的车: @SelectedCar
</p>

@code {
    public string? SelectedCar { get; set; }

    private void SelectedCarsChanged(ChangeEventArgs e)
    {
        SelectedCar = e.Value?.ToString();
    }
} *@

@* <p>
    <input @bind="inputValue" />
</p>

<p>
    <code>inputValue</code>: @inputValue
</p>

@code {
    private int inputValue = 123;
} *@


<p>
    <label>
        <code>年月日</code> 格式:
        <input @bind="startDate" @bind:format="yyyy年MM月dd日" />
    </label>
</p>

<p>
    <code>startDate</code>: @startDate
</p>

@code {
    private DateTime startDate = DateTime.Now;
}